﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Diagnostics;
using System.Xml.Linq;

namespace WeChat.Common
{
    public static class ExtentionClass
    {
        //public static bool IsNameWindowOpen<T>(string name = "") where T : Window
        //{
        //    return string.IsNullOrEmpty(name)
        //       ? Application.Current.Windows.OfType<T>().Any()
        //       : Application.Current.Windows.OfType<T>().All(w => w.Name.Equals(name));
        //}

        //public static bool IsWindowOpen1(Window windowObjcet)
        //{
        //    foreach (Window item in Application.Current.Windows)
        //    {
        //        Console.WriteLine(item.Name);
        //        if (windowObjcet.Name.Equals(item.Name)) return true;
        //    }
        //    return false;
        //}

        public static bool IsWindowOpen(this Window window)
        {
            //var f = typeof(Window).GetField("_showingAsDialog", BindingFlags.Instance | BindingFlags.NonPublic);
            //return f != null && (bool)f.GetValue(window);
            return Application.Current.Windows.Cast<Window>().Any(x => x == window);
        }
    }
}
